<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<PoserLoot.Web.Models.Entry>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%= Html.Encode(Model.Appellation) %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="LeftContent" runat="server">
    <% Html.RenderPartial("CategoryIndex", ViewData["IEnumerable<Category>"]); %>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script src="/Scripts/jquery.galleriffic.min.js" type="text/javascript"></script>

    <link href="/Content/galleriffic.css" rel="stylesheet" type="text/css" />
    <div id="gridTopic" class="topic">
        <h2>
            <%= Html.Encode(Model.Code) %>,
            <%= Html.Encode(Model.Appellation) %></h2>
    </div>
    <div id="toolbar">
        <%=Html.ActionLink("[Edit]", "Edit", new { id = Model.EntryId })%></div>
    <div>
        <p>
            ReferenceUrl: <a href="<%=Model.ReferenceUrl %>" target="_blank">
                <%=Model.ReferenceUrl %></a></p>
        <div>
            <div id="gallery" class="content">
                <div id="controls" class="controls">
                </div>
                <div id="loading" class="loader">
                </div>
                <div id="slideshow" class="slideshow">
                </div>
                <div id="caption" class="embox">
                </div>
            </div>
            <div id="thumbs" class="navigation">
                <ul class="thumbs noscript">
                    <% foreach (var i in ViewData["IEnumerable<Gallery>"] as IEnumerable<PoserLoot.Web.Models.Gallery>)
                       { %>
                    <li><a class="thumb" href="<%=Url.Action("Original", "Gallery", new { id = i.GalleryId }) %>">
                        <img src="<%=Url.Action("Thumbnail", "Gallery", new { id = i.GalleryId }) %>" alt="" />
                    </a>
                        <div class="caption">
                            <%= Html.ActionLink("[Delete]", "Delete", "Gallery", new { id = i.GalleryId }, null) %>
                            |
                            <% if (i == Model.Thumbnail)
                               { %>
                            Thumbnail
                            <% }
                               else
                               { %>
                            <%= Html.ActionLink("[Set Thumbnail]", "SetThumbnail", "Entry", new { id = Model.EntryId, galleryId = i.GalleryId }, null)%>
                            <% } %>
                        </div>
                    </li>
                    <% } %>
                    <li>
                        <%= Html.ActionLink("[Add Image]", "Create", "Gallery", new { id = Model.EntryId }, null)%>
                    </li>
                </ul>
            </div>
        </div>
        <div class="clear">
        </div>
        <div class="entrydiv">
            <ul>
                <% List<string> units = new List<string>() { "B", "KB", "MB", "GB", "TB" };

                   foreach (var i in ViewData["IEnumerable<File>"] as IEnumerable<PoserLoot.Web.Models.File>)
                   {
                       string[] s = i.Path.Split(new char[] { '|' });
                       string filename = Server.UrlDecode(s[2]);
                       double filesize = Double.Parse(s[3]);
                       int filesizeUnit = 0;

                       while (filesize > 1024 || filesizeUnit > 4)
                       {
                           filesize /= 1024;
                           filesizeUnit++;
                       }
                           
                %>
                <li>
                    <%= Html.ActionLink("[Delete]", "Delete", "File", new { id = i.FileId }, null)%>
                    -
                    <%= filesize.ToString("F") + units[filesizeUnit] %>
                    - <a href="<%= i.Path %>" target="_blank">
                        <%= filename %></a> </li>
                <% } %>
                <li>
                    <%= Html.ActionLink("[Add File]", "Create", "File", new { id = Model.EntryId }, null) %></li>
            </ul>
        </div>
        <div class="clear">
        </div>
        <div class="entrydiv">
            <%= Model.Summary%>
        </div>
        <div class="clear">
        </div>
        <div class="entrydiv">
            <%= Model.Description %>
        </div>
        <div class="clear">
        </div>
        <div class="entrydiv">
            <% Html.RenderPartial("CommentIndex", ViewData["IEnumerable<Comment>"]); %>
            <p>
                <%= Html.ActionLink("Post Comment", "Create", "Comment", new { id = Model.EntryId }, null)%>
            </p>
        </div>
    </div>

    <script type="text/javascript">
        // We only want these styles applied when javascript is enabled
        $('div.navigation').css({ 'width': '150px', 'float': 'left' });
        $('div.content').css('display', 'block');

        // Initially set opacity on thumbs and add
        // additional styling for hover effect on thumbs
        var onMouseOutOpacity = 0.67;
        $('#thumbs ul.thumbs li').css('opacity', onMouseOutOpacity)
				.hover(
					function() {
					    $(this).not('.selected').fadeTo('fast', 1.0);
					},
					function() {
					    $(this).not('.selected').fadeTo('fast', onMouseOutOpacity);
					}
				);

        $(document).ready(function() {
            // Initialize Advanced Galleriffic Gallery
            var galleryAdv = $('#gallery').galleriffic('#thumbs', {
                delay: 2000,
                numThumbs: 4,
                preloadAhead: 10,
                enableTopPager: true,
                enableBottomPager: true,
                imageContainerSel: '#slideshow',
                controlsContainerSel: '#controls',
                captionContainerSel: '#caption',
                loadingContainerSel: '#loading',
                renderSSControls: true,
                renderNavControls: true,
                playLinkText: 'Play Slideshow',
                pauseLinkText: 'Pause Slideshow',
                prevLinkText: '&lsaquo; Previous Photo',
                nextLinkText: 'Next Photo &rsaquo;',
                nextPageLinkText: 'Next &rsaquo;',
                prevPageLinkText: '&lsaquo; Prev',
                enableHistory: true,
                autoStart: false,
                onChange: function(prevIndex, nextIndex) {
                    $('#thumbs ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);
                },
                onTransitionOut: function(callback) {
                    $('#caption').fadeOut('fast');
                    $('#slideshow').fadeOut('fast', callback);
                },
                onTransitionIn: function() {
                    $('#slideshow, #caption').fadeIn('fast');
                },
                onPageTransitionOut: function(callback) {
                    $('#thumbs ul.thumbs').fadeOut('fast', callback);
                },
                onPageTransitionIn: function() {
                    $('#thumbs ul.thumbs').fadeIn('fast');
                }
            });
        });
    </script>

</asp:Content>
